<template>
    <a-modal :title="'更新文档'" :visible="true" width="400px" @ok="submit" @cancel="reset">
        <div style="display:flex;    justify-content: center;">
            <fileUpload style="display:flex;flex-wrap: wrap;width:100px;marfin-left:10px" :uploadParams="getUploadParams()"
                :isMultiple="true" :number="1" @fileChange1="fileChange1" v-model="list"></fileUpload>
        </div>
    </a-modal>
</template>
    
<script>
import fileUpload from './uploadfile.vue'
import globalData from '@/assets/js/common'
import { axios } from '@/utils/request'

export default {
    components: {
        fileUpload,
    },
    props: {
        id: {
            type: Number,
            default: null,
            required: false,
        },
        type: {
            type: Number,
            default: null,
            required: false,
        },
    },
    data() {
        return {
            urlKey: 'basemgt-material/',
            list: [],
        }
    },

    created() {

    },
    computed: {
        jobNumber() {
            return this.$store.getters.userInfo.workNo || ''
        }
    },
    methods: {
        getUploadParams() {
            return { ...globalData.uploadParams }
        },
        fileChange1(list) {
            this.list = list
            console.log(this.list);
        },
        reset() {
            this.list = []
            this.$emit('closeExport')
        },

        submit() {
            if (!this.list.length) {
                this.$message.error('请先选择文件！')
            } else {
                const formData = new FormData()
                this.list.forEach((file) => {
                    formData.append(`file`, file.originFileObj);
                });
                formData.append('id', this.id)
                formData.append('type', this.type)
                formData.append('client', 2)
                const apiBaseUrl = window._CONFIG['domianURL'] || "/jeecg-boot";
                axios({
                    url: apiBaseUrl + '/api/gateway/basemgt-material/sample-upload-file/update',
                    method: 'post',
                    data: formData,
                    contentType: false,
                    cache: false,
                    processData: false,//用于对data参数进行序列化处理 这里必须false
                    // headers: { 'Content-Type': 'multipart/form-data; boundary=----WebKitFormBoundarynl6gT1BKdPWIejNq' }
                }).then(res => {
                    if (res.code == 200) {
                        this.$message.success('更新成功')
                        this.reset()
                    } else {
                        this.$message.warning(res.msg || '更新失败')
                    }
                    this.loading = false
                })
            }

        }
    }
}
</script>
<style scoped>
.info-action {
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: center;
    justify-content: flex-end;
}

.ml-20 {
    margin-left: 20px;
}

.dynamic-delete-button {
    cursor: pointer;
    position: absolute;
    right: -40px;
    top: -4px;
    font-size: 24px;
    color: #999;
    transition: all 0.3s;
}

.dynamic-delete-button:hover {
    color: #777;
}

.dynamic-delete-button[disabled] {
    cursor: not-allowed;
    opacity: 0.5;
}
</style>